package wli.app.util;

import java.util.*;
import static org.junit.Assert.*;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class StringStatisticsUtilTest {

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testSetString() {
		StringStatisticsUtil stut = new StringStatisticsUtil();
		stut.setString("run fox and fox Run and run and run. run run");
		System.out.println("test setInput =[ "+stut.getInputString()+" ]");
	}

	@Test
	public void testGetInput() {
		StringStatisticsUtil stut = new StringStatisticsUtil();
		stut.setString("run fox and fox Run and run and run. run run");
		System.out.println("Input String:"+stut.getInputString());
	}
	
	@Test
	public void testGetWordsVector() {
		StringStatisticsUtil stut = new StringStatisticsUtil();
		stut.setString("run fox and fox Run and run and run. run run");
		Vector<StringStatistics> v = stut.getWordsVector();
		StringStatistics ssr = null;
		Enumeration<StringStatistics> enums = v.elements();
		while (enums.hasMoreElements()) {
			ssr = enums.nextElement();
			System.out.println ("V-Name="+ssr.getName());
			System.out.println ("V-Total="+ssr.getTotal());
		}
	}
	
	
	@Test
	public void testGetWordsHashtable() {
		StringStatisticsUtil stut = new StringStatisticsUtil();
		stut.setString("run fox and fox Run and run and run. run run");
		System.out.println("Words Hashtable:"+stut.getWordsHashtable());
	}
	
	@Test
	public void testGetWordsArrayList() {
		StringStatisticsUtil stut = new StringStatisticsUtil();
		stut.setString("run fox and fox Run and run and run. run run will will will");
		List<StringStatistics> ls =  stut.getWordsArrayList(); 
		ArrayList<StringStatistics> alist = (ArrayList<StringStatistics>)stut.getWordsArrayList(); 
		System.out.println("total records:"+alist.size());
		System.out.println("Before Sort..........................");
		StringStatistics ssr = null;
		Iterator<StringStatistics> it = alist.iterator();
		while(it.hasNext()) {
			ssr = it.next();
			System.out.println("["+ssr.getTotal()+"]"+ssr.getName());
		}
		
		System.out.println("After Sort..........................");
		Collections.sort(ls);

		it = ls.iterator();
		while(it.hasNext()) {
			ssr = it.next();
			System.out.println("["+ssr.getTotal()+"]"+ssr.getName());
		}
	}
}
